;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
;;;
;;; This program is free software.  You may run, copy, modify, and
;;; redistribute it under the terms of the GNU General Purpose License
;;; (GPL) version 3, or any later version.

(define-module (test-regular)
  #:use-module (derivative language regular)
  #:use-module (srfi srfi-64))

(test-begin "regular")
(test-assert "null language"
  (and (δ 'eps)
       (recognize? "" 'eps)))
(test-assert "nullable"
  (and (δ (alt #\x 'eps))
       (δ (D #\x (alt #\x #\y)))))
(test-assert "not nullable"
  (not (or (δ (alt #\x #\y))
	   (δ (cat #\x 'eps))
	   (δ ab-lang))))

(test-assert "language: x - \"\"" (recognize? "" x-lang))
(test-assert "language: x - \"x\"" (recognize? "x" x-lang))
(test-assert "language: x - \"xxxxx\"" (recognize? "xxxxx" x-lang))
(test-assert "language: x - \"yyyyy\"" (not (recognize? "yyyyy" x-lang)))

(test-assert "language: ab - \"\"" (not (recognize? "" ab-lang)))
(test-assert "language: ab - \"a\"" (recognize? "a" ab-lang))
(test-assert "language: ab - \"b\"" (recognize? "b" ab-lang))
(test-assert "language: ab - \"ab\"" (recognize? "ab" ab-lang))
(test-assert "language: ab - \"ba\"" (recognize? "ba" ab-lang))
(test-assert "language: ab - \"aaababb\"" (recognize? "aaababb" ab-lang))
(test-assert "language: ab - \"bababbaaa\"" (recognize? "bababbaaa" ab-lang))

(test-assert "language: phone numbers"
  (and (recognize? "234.567.8901" phone-lang)
       (recognize? "(234)567-8901" phone-lang)
       (recognize? "234-567-8901" phone-lang)
       (recognize? "1.234.567.8901x2345" phone-lang)
       (recognize? "+1-234-567-8901" phone-lang)
       (not (recognize? "1/234/567/8901" phone-lang))))
  
(test-end "regular")
